﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Collections;

namespace l1cs.server.utils
{
    class IterableNodeList : IEnumerable
    {
        private XmlNodeList _list;

        public int Count
        {
            get
            {
                return _list.Count;
            }
        }

        private class MyIterator : IEnumerator
        {
            private int _index = -1;

            private IterableNodeList _links;

            public MyIterator( IterableNodeList links )
            {
                _links = links;
            }

            public bool MoveNext()
            {
                if ( _index < _links._list.Count - 1 )
                {
                    _index++;
                    return true;
                }
                return false;
            }

            public object Current
            {
                get
                {
                    //if ( _index == -1 )
                    //{
                    return null;
                    //}
                    //return _links[_index];
                }
            }

            public void Reset()
            {
                _index = -1;
            }

            //    @Override
            //    public boolean hasNext() {
            //        return _idx < _list.getLength();
            //    }

            //    @Override
            //    public Node next() {
            //        if (!hasNext()) {
            //            throw new NoSuchElementException();
            //        }
            //        return _list.item(_idx++);
            //    }

            //    @Override
            //    public void remove() {
            //        throw new UnsupportedOperationException();
            //    }
        }

        public IterableNodeList( XmlNodeList list )
        {
            _list = list;
        }

        //@Override
        //public Iterator<Node> iterator() {
        //    return new MyIterator();
        //}
        public IEnumerator GetEnumerator()
        {
            return new MyIterator( this );
        }
    }
}
